home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / gr / gr.c < prev    next >
C/C++ Source or Header  |  1991-09-01  |  3KB  |  87 lines

  1. /* This program opens a custom screen and window with menus */
  2. /* The Project menu item "Quit" is the only item on that menu implemented */
  3. /* The Misc menu items all work and demonstrate rudimentary drawing */
  4. /* and color map calls */
  5.  
  6. #include "intuition.h"
  7.  
  8. int quit; /* global flag to quit program */
  9.  
  10. project(long item,long subitem)
  11. {
  12.     switch(item) {
  13.         case 4: quit=1;break;
  14.         default: puts("Not implemented");
  15.     }
  16. }
  17.  
  18. misc(long item,long subitem)
  19. {
  20.     long y,x1,y1,x2,y2,i;
  21.     extern struct RastPort *RastPort;
  22.     extern struct Window *Window;
  23.     extern struct Screen *Screen;
  24.  
  25.     switch(item) {
  26.         case 0:
  27.             /* get the coordinates inside the borders */
  28.             x1 = Window->LeftEdge + Window->BorderLeft - 1;
  29.             x2 = Window->Width - Window->BorderRight + 1;
  30.             y1 = Window->TopEdge + Window->BorderTop -1;
  31.             y2 = Window->Height - Window->BorderBottom;
  32.             for(y=y1;y<=y2;y++) { /* Draw color map */
  33.                 SetAPen(RastPort,(y-y1)/24);
  34.                 Move(RastPort,x1,y);
  35.                 Draw(RastPort,x2,y);
  36.             }
  37.             break;
  38.         case 1: /* Setup an RGB colormap */
  39.             SetRGB4(&Screen->ViewPort,0,0,0,0);
  40.             SetRGB4(&Screen->ViewPort,1,0,0,7);
  41.             SetRGB4(&Screen->ViewPort,2,0,0,11);
  42.             SetRGB4(&Screen->ViewPort,3,0,0,15);
  43.             SetRGB4(&Screen->ViewPort,4,0,7,0);
  44.             SetRGB4(&Screen->ViewPort,5,0,11,0);
  45.             SetRGB4(&Screen->ViewPort,6,0,15,0);
  46.             SetRGB4(&Screen->ViewPort,7,0,7,7);
  47.             SetRGB4(&Screen->ViewPort,8,0,11,11);
  48.             SetRGB4(&Screen->ViewPort,9,0,15,15);
  49.             SetRGB4(&Screen->ViewPort,10,7,7,0);
  50.             SetRGB4(&Screen->ViewPort,10,11,11,0);
  51.             SetRGB4(&Screen->ViewPort,12,15,15,0);
  52.             SetRGB4(&Screen->ViewPort,13,7,0,7);
  53.             SetRGB4(&Screen->ViewPort,14,11,0,11);
  54.             SetRGB4(&Screen->ViewPort,15,15,0,15);
  55.             break;
  56.         case 2: /* Setup a Grey Level colormap */
  57.             for(i=0;i<16;i++) SetRGB4(&Screen->ViewPort,i,i,i,i);
  58.             break;
  59.         default: puts("Not implemented");
  60.     }
  61. }
  62.  
  63. main()
  64. {
  65.     long choice,menu,item,subitem;
  66.  
  67.     init_libs(); /* open the libraries, screen, and window */
  68.     init_screen();
  69.     init_window();
  70.  
  71.     while(choice=handle_user(&menu,&item,&subitem) && quit==0) {
  72.         switch(choice) {
  73.             case 1: /* Menu pick */
  74.                 /* subitem will equal 31 if no subitem was attached to menu */
  75.                 switch(menu) {
  76.                     case 0: project(item,subitem);break;
  77.                     case 1: misc(item,subitem);break;
  78.                 }
  79.                 break;
  80.             default:
  81.                 printf("choice = %ld\n",choice);
  82.                 break;
  83.         }
  84.     }
  85.     close_all();
  86. }
  87.